package org.example;
import java.awt.*;
import java.awt.datatransfer.Clipboard;
import java.awt.datatransfer.StringSelection;
import java.awt.event.InputEvent;
import java.awt.event.KeyEvent;
import java.util.concurrent.TimeUnit;



public class Main {
    private static Robot robot;
    public static void main(String[] args) throws InterruptedException {
        //对鼠标操作
        try {
            robot = new Robot();

        } catch (Exception e) {
            // TODO: handle exception
            e.printStackTrace();
        }
        robot.delay(20);
        robot.mouseMove(400, 200);//鼠标移动到的位置，（0,0)在左上角。
        robot.mousePress(InputEvent.BUTTON3_MASK); //点击鼠标右键
        robot.mousePress(InputEvent.BUTTON1_MASK); //点击鼠标左键
        robot.delay(20); //可以理解为等待
        robot.mouseRelease(InputEvent.BUTTON3_MASK); //关闭
        robot.mouseRelease(InputEvent.BUTTON1_MASK); //关闭
        //对键盘操作
        try {
            robot=new Robot();
        } catch (Exception e) {
            // TODO 自动生成的 catch 块
            e.printStackTrace();
        }
        //快捷键windows+R
        robot.keyPress(KeyEvent.VK_WINDOWS);
        robot.keyPress(KeyEvent.VK_R);
        robot.delay(20);
        robot.keyRelease(KeyEvent.VK_WINDOWS);
        robot.keyRelease(KeyEvent.VK_R);
        robot.delay(20);
        //创建系统剪贴板，并设置内容，相当于把内容放入系统的剪切板中，用户也可以手动 ctrl + v 找他
        StringSelection stringSelection = new StringSelection("mstsc");
        Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
        clipboard.setContents(stringSelection, null);
        TimeUnit.SECONDS.sleep(1);//程序等待1秒
        //快捷键Ctrl+R
        robot.delay(20);
        robot.keyPress(KeyEvent.VK_CONTROL);
        robot.keyPress(KeyEvent.VK_V);
        robot.delay(20);
        robot.keyRelease(KeyEvent.VK_CONTROL);
        robot.keyRelease(KeyEvent.VK_V);
        robot.delay(20);
        //确定按钮
        TimeUnit.SECONDS.sleep(1);
        robot.keyPress(KeyEvent.VK_ENTER);
        robot.delay(20);
        robot.keyRelease(KeyEvent.VK_ENTER);
        robot.delay(20);
        //给剪切板写入"acdc@Passw0rd1"内容
        stringSelection = new StringSelection("acdc@Passw0rd1");
        clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
        clipboard.setContents(stringSelection, null);
        robot.delay(20);
        TimeUnit.SECONDS.sleep(2);
        robot.keyPress(KeyEvent.VK_CONTROL);
        robot.keyPress(KeyEvent.VK_V);
        robot.delay(20);
        robot.keyRelease(KeyEvent.VK_CONTROL);
        robot.keyRelease(KeyEvent.VK_V);
        robot.delay(20);
        TimeUnit.SECONDS.sleep(3);
        robot.keyPress(KeyEvent.VK_ENTER);
        robot.delay(20);
        robot.keyRelease(KeyEvent.VK_ENTER);
        robot.delay(20);
    }
}